package com.beemans.common.utils

import java.util.concurrent.TimeoutException

/**
 * @author tiamosu
 * @date 2021/8/26.
 */
object CrashHandler {

    /**
     * Java Crash 捕获，自定义 UncaughtExceptionHandler 初始化，处理如下
     */
    fun init() {
        Thread.setDefaultUncaughtExceptionHandler { t, e ->
            if (t.name.equals("FinalizerWatchdogDaemon") && e is TimeoutException) {
                //ignore it
            } else {
                val defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
                defaultUncaughtExceptionHandler?.uncaughtException(t, e)
            }
        }
    }
}